<template>
  <div  class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icons-content" v-for="item of page" :key="item.id">
          <div class="icons-imgs-container">
            <img class="icons-img-content" :src="item.imgUrl" alt="">
            <p class="icons-desc">{{item.desc}}</p>
          </div>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: {
      type: Array
    }
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.map((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/variable.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    width 100%
    height 0
    padding-bottom 50%
  .icons >>> .swiper-pagination
    bottom 0
  .icons
    margin-top 10px
  .icons-content
    float left
    width 25%
    padding-bottom 25%
    height 0
    overflow hidden
    position relative
  .icons-imgs-container
    position absolute
    width 100%
    top 0
    left 0
    bottom 22px
    box-sizing border-box
    padding 28px
    text-align center
    .icons-img-content
      height 100%
    .icons-desc
      position absolute
      width 100%
      left 0
      bottom 0
      height 22px
      line-height 22px
      font-size 16px
      ellipsis()
      $descTextColor
</style>
